Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / feature / map / src / androidMain / kotlin / org / meshtastic / feature / map / layers / MapLayerPicker.android.kt

Displaying Raw • Download

feature/map/src/androidMain/kotlin/org/meshtastic/feature/map/layers/MapLayerPicker.android.kt renovate/fastlane-2.x-lockfile (056eed64) Text, 4.06 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.map.layers

Tff7b72import T7ee787android.app.Activity
Tff7b72import T7ee787android.content.Context
Tff7b72import T7ee787android.content.Intent
Tff7b72import T7ee787android.net.Uri
Tff7b72import T7ee787android.provider.OpenableColumns
Tff7b72import T7ee787androidx.activity.compose.rememberLauncherForActivityResult
Tff7b72import T7ee787androidx.activity.result.contract.ActivityResultContracts
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.ui.platform.LocalContext
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787org.meshtastic.core.common.util.nowMillis

Tf0883e@Composable
Tff7b72actual Tff7b72fun Td2a8ffrememberMapLayerPickerTb4b4b4(Te6edf3onPickTb4b4b4: Tb4b4b4(Te6edf3PickedMapFileTb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4)Tb4b4b4: Te6edf3MapLayerPickerLauncher Tb4b4b4{
Tff7b72val Te6edf3context Tff7b72= Te6edf3LocalContextTb4b4b4.Te6edf3current
Tff7b72val Te6edf3launcher Tff7b72=
Te6edf3rememberLauncherForActivityResultTb4b4b4(Te6edf3ActivityResultContractsTb4b4b4.Te6edf3StartActivityForResultTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{ Te6edf3result Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3resultTb4b4b4.Te6edf3resultCode Tff7b72=Tff7b72= Te6edf3ActivityTb4b4b4.Te6edf3RESULT_OKTb4b4b4) Tb4b4b4{
Te6edf3resultTb4b4b4.Te6edf3dataTff7b72?.Te6edf3dataTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3onPickTb4b4b4(Tffa657itTb4b4b4.Te6edf3toPickedMapFileTb4b4b4(Te6edf3contextTb4b4b4)Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Tff7b72return Te6edf3MapLayerPickerLauncher Tb4b4b4{
T8b949e// Providers hand back generic MIME types for perfectly good map files, so the extension is validated after
T8b949e// selection rather than filtered here.
Te6edf3launcherTb4b4b4.Te6edf3launchTb4b4b4(
Te6edf3IntentTb4b4b4(Te6edf3IntentTb4b4b4.Te6edf3ACTION_OPEN_DOCUMENTTb4b4b4)Tb4b4b4.Te6edf3apply Tb4b4b4{
Te6edf3addCategoryTb4b4b4(Te6edf3IntentTb4b4b4.Te6edf3CATEGORY_OPENABLETb4b4b4)
Te6edf3type Tff7b72= Ta5d6ff"Ta5d6ff*/*Ta5d6ff"
Tb4b4b4}Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Wrap a picked `content://` as a [PickedMapFile] for the layer store.
*
* The store never sees a [Uri]: resolving one is exactly the platform knowledge it exists to avoid, so the read is
* handed over as a lambda instead. The MIME type is the fallback for the extension rather than being used only when the
* display name is absent — a picked file with no dot in its name used to resolve to no type and be rejected.
*/
Tff7b72fun Te6edf3UriTb4b4b4.Td2a8fftoPickedMapFileTb4b4b4(Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4)Tb4b4b4: Te6edf3PickedMapFile Tb4b4b4{
Tff7b72val Te6edf3displayName Tff7b72= Te6edf3getFileNameTb4b4b4(Te6edf3contextTb4b4b4)
Tff7b72return Te6edf3PickedMapFileTb4b4b4(
Te6edf3displayName Tff7b72= Te6edf3displayNameTb4b4b4,
Te6edf3extensionOrMime Tff7b72=
Te6edf3displayNameTb4b4b4.Te6edf3substringAfterLastTb4b4b4(Ta5d6ff'.'Tb4b4b4, Ta5d6ff"Ta5d6ff"Tb4b4b4)Tb4b4b4.Te6edf3ifBlank Tb4b4b4{
Te6edf3contextTb4b4b4.Te6edf3contentResolverTb4b4b4.Te6edf3getTypeTb4b4b4(Tff7b72thisTb4b4b4)Tff7b72?.Te6edf3substringAfterLastTb4b4b4(Ta5d6ff'/'Tb4b4b4)
Tb4b4b4}Tb4b4b4,
Te6edf3read Tff7b72= Tb4b4b4{ Te6edf3contextTb4b4b4.Te6edf3contentResolverTb4b4b4.Te6edf3openInputStreamTb4b4b4(Tff7b72thisTb4b4b4)Tff7b72?.Te6edf3use Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3readBytesTb4b4b4(Tb4b4b4) Tb4b4b4} Tb4b4b4}Tb4b4b4,
Tb4b4b4)
Tb4b4b4}

T8b949e/**
* Resolve a display file name for [this] URI, querying the content resolver for `content://` URIs. Untrusted providers
* (share/open-with from other apps) can throw or return a null display name, so guard both and fall back to the URI's
* last path segment.
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffNestedBlockDepthTa5d6ff"Tb4b4b4)
Tff7b72fun Te6edf3UriTb4b4b4.Td2a8ffgetFileNameTb4b4b4(Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4)Tb4b4b4: Tffa657String Tb4b4b4{
Tff7b72var Te6edf3name Tff7b72= Te6edf3lastPathSegment Tff7b72?: Ta5d6ff"Ta5d6fflayer_Tffd700$Te6edf3nowMillisTa5d6ff"
Tff7b72if Tb4b4b4(Te6edf3scheme Tff7b72=Tff7b72= Ta5d6ff"Ta5d6ffcontentTa5d6ff"Tb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3contextTb4b4b4.Te6edf3contentResolverTb4b4b4.Te6edf3queryTb4b4b4(Tff7b72thisTb4b4b4, Tff7b72nullTb4b4b4, Tff7b72nullTb4b4b4, Tff7b72nullTb4b4b4, Tff7b72nullTb4b4b4)Tff7b72?.Te6edf3use Tb4b4b4{ Te6edf3cursor Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3cursorTb4b4b4.Te6edf3moveToFirstTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3displayNameIndex Tff7b72= Te6edf3cursorTb4b4b4.Te6edf3getColumnIndexTb4b4b4(Te6edf3OpenableColumnsTb4b4b4.Te6edf3DISPLAY_NAMETb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3displayNameIndex Tff7b72!Tff7b72= Tff7b72-T79c0ff1Tb4b4b4) Tb4b4b4{
Te6edf3cursorTb4b4b4.Te6edf3getStringTb4b4b4(Te6edf3displayNameIndexTb4b4b4)Tff7b72?.Te6edf3let Tb4b4b4{ Te6edf3name Tff7b72= Tffa657it Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
T8b949e// Keep the lastPathSegment fallback assigned above rather than crashing the import.
Te6edf3LoggerTb4b4b4.Te6edf3withTagTb4b4b4(Ta5d6ff"Ta5d6ffMapLayerTa5d6ff"Tb4b4b4)Tb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffFailed to resolve display name for content URI; using fallbackTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tff7b72return Te6edf3name
Tb4b4b4}

Served by rngit 1.5.2 - Generated in 0.05s